<template>
  <div class="cart">
    <el-table
      class="cart-table"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="课程" width="520">
        <template slot-scope="scope">
          <div id="course">
            <img src="https://img1.mukewang.com/szimg/5d14215f08545a6b06000338.jpg" alt />
            <p>{{ scope.row.title }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="金额" width="220">
        <template slot-scope="scope">￥&nbsp;{{ scope.row.price }}</template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip>
        <template>删除</template>
      </el-table-column>
    </el-table>
    <div class="operation">
      <el-button type="primary" @click="toggleSelection([tableData[1], tableData[2]])">结算</el-button>
      <el-button @click="toggleSelection()">取消选择</el-button>
    </div>
  </div>
</template>

<script>
import { Table, TableColumn, Button } from "element-ui";
export default {
  components: {
    ElTable: Table,
    ElTableColumn: TableColumn,
    ElButton: Button
  },
  data() {
    return {
      tableData: [
        {
          title: "《初中物理》力的相互作用",
          price: "25",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          title: "《初中物理》力的相互作用",
          price: "25",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          title: "《初中物理》力的相互作用",
          price: "25",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          title: "《初中物理》力的相互作用",
          price: "25",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          title: "《初中物理》力的相互作用",
          price: "25",
          address: "上海市普陀区金沙江路 1518 弄"
        }
      ],
      multipleSelection: []
    };
  },

  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>

<style lang="scss" scoped>
.cart {
  .cart-table {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
  }
  .operation {
    padding: 30px 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
}
#course {
  padding: 20px 0;
  display: flex;
  justify-content: flex-start;
  p {
    font-size: 16px;
    color: #07111b;
    line-height: 24px;
  }
  img {
    border-radius: 8px;
    height: 100px;
    width: 200px;
  }
}
</style>

<style lang="scss">
.el-checkbox__inner {
  width: 20px;
  height: 20px;
}
.el-checkbox__input.is-checked .el-checkbox__inner::after {
  transform: translateY(2px) translateX(3px) rotate(45deg) scale(1.5);
}
</style>